Passed
Pull Request — master (#45)
by
unknown
06:19
created

alert.js ➔ _interopDefaultLegacy   B

Complexity

Conditions 7

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 1
dl 0
loc 1
rs 8
c 0
b 0
f 0
1
/*!
2
  * Bootstrap alert.js v4.5.3 (https://getbootstrap.com/)
3
  * Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', './util.js'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Alert = factory(global.jQuery, global.Util));
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
10
}(this, (function ($, Util) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
  var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
16
17
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
18
19
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
20
  /**
21
   * ------------------------------------------------------------------------
22
   * Constants
23
   * ------------------------------------------------------------------------
24
   */
25
26
  var NAME = 'alert';
27
  var VERSION = '4.5.3';
28
  var DATA_KEY = 'bs.alert';
29
  var EVENT_KEY = "." + DATA_KEY;
30
  var DATA_API_KEY = '.data-api';
31
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
32
  var SELECTOR_DISMISS = '[data-dismiss="alert"]';
33
  var EVENT_CLOSE = "close" + EVENT_KEY;
34
  var EVENT_CLOSED = "closed" + EVENT_KEY;
35
  var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
36
  var CLASS_NAME_ALERT = 'alert';
37
  var CLASS_NAME_FADE = 'fade';
38
  var CLASS_NAME_SHOW = 'show';
39
  /**
40
   * ------------------------------------------------------------------------
41
   * Class Definition
42
   * ------------------------------------------------------------------------
43
   */
44
45
  var Alert = /*#__PURE__*/function () {
46
    function Alert(element) {
47
      this._element = element;
48
    } // Getters
49
50
51
    var _proto = Alert.prototype;
52
53
    // Public
54
    _proto.close = function close(element) {
55
      var rootElement = this._element;
56
57
      if (element) {
58
        rootElement = this._getRootElement(element);
59
      }
60
61
      var customEvent = this._triggerCloseEvent(rootElement);
62
63
      if (customEvent.isDefaultPrevented()) {
64
        return;
65
      }
66
67
      this._removeElement(rootElement);
68
    };
69
70
    _proto.dispose = function dispose() {
71
      $__default['default'].removeData(this._element, DATA_KEY);
72
      this._element = null;
73
    } // Private
74
    ;
75
76
    _proto._getRootElement = function _getRootElement(element) {
77
      var selector = Util__default['default'].getSelectorFromElement(element);
78
      var parent = false;
79
80
      if (selector) {
81
        parent = document.querySelector(selector);
82
      }
83
84
      if (!parent) {
85
        parent = $__default['default'](element).closest("." + CLASS_NAME_ALERT)[0];
86
      }
87
88
      return parent;
89
    };
90
91
    _proto._triggerCloseEvent = function _triggerCloseEvent(element) {
92
      var closeEvent = $__default['default'].Event(EVENT_CLOSE);
93
      $__default['default'](element).trigger(closeEvent);
94
      return closeEvent;
95
    };
96
97
    _proto._removeElement = function _removeElement(element) {
98
      var _this = this;
99
100
      $__default['default'](element).removeClass(CLASS_NAME_SHOW);
101
102
      if (!$__default['default'](element).hasClass(CLASS_NAME_FADE)) {
103
        this._destroyElement(element);
104
105
        return;
106
      }
107
108
      var transitionDuration = Util__default['default'].getTransitionDurationFromElement(element);
109
      $__default['default'](element).one(Util__default['default'].TRANSITION_END, function (event) {
110
        return _this._destroyElement(element, event);
111
      }).emulateTransitionEnd(transitionDuration);
112
    };
113
114
    _proto._destroyElement = function _destroyElement(element) {
115
      $__default['default'](element).detach().trigger(EVENT_CLOSED).remove();
116
    } // Static
117
    ;
118
119
    Alert._jQueryInterface = function _jQueryInterface(config) {
120
      return this.each(function () {
121
        var $element = $__default['default'](this);
122
        var data = $element.data(DATA_KEY);
123
124
        if (!data) {
125
          data = new Alert(this);
126
          $element.data(DATA_KEY, data);
127
        }
128
129
        if (config === 'close') {
130
          data[config](this);
131
        }
132
      });
133
    };
134
135
    Alert._handleDismiss = function _handleDismiss(alertInstance) {
136
      return function (event) {
137
        if (event) {
138
          event.preventDefault();
139
        }
140
141
        alertInstance.close(this);
142
      };
143
    };
144
145
    _createClass(Alert, null, [{
146
      key: "VERSION",
147
      get: function get() {
148
        return VERSION;
149
      }
150
    }]);
151
152
    return Alert;
153
  }();
154
  /**
155
   * ------------------------------------------------------------------------
156
   * Data Api implementation
157
   * ------------------------------------------------------------------------
158
   */
159
160
161
  $__default['default'](document).on(EVENT_CLICK_DATA_API, SELECTOR_DISMISS, Alert._handleDismiss(new Alert()));
162
  /**
163
   * ------------------------------------------------------------------------
164
   * jQuery
165
   * ------------------------------------------------------------------------
166
   */
167
168
  $__default['default'].fn[NAME] = Alert._jQueryInterface;
169
  $__default['default'].fn[NAME].Constructor = Alert;
170
171
  $__default['default'].fn[NAME].noConflict = function () {
172
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
173
    return Alert._jQueryInterface;
174
  };
175
176
  return Alert;
177
178
})));
179
//# sourceMappingURL=alert.js.map
180